package hu.debrecen.adastra.card.web.resolver;

import hu.debrecen.adastra.card.service.SocialUserService;
import hu.debrecen.adastra.card.util.SignInUtils;
import hu.debrecen.adastra.card.web.domain.UserSocialReference;

import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.ModelAndViewContainer;

public class UserSocialReferenceArgumentResolver extends AutowiredHandlerAnnotationArgumentResolver {

	private final SocialUserService socialUserService;

	public UserSocialReferenceArgumentResolver(final SocialUserService socialUserService) {
		this.socialUserService = socialUserService;
	}

	@Override
	public boolean supportsParameter(final MethodParameter paramMethodParameter) {
		return super.supportsParameter(paramMethodParameter) && paramMethodParameter.getParameterType().equals(UserSocialReference.class);
	}

	@Override
	public Object resolveArgument(final MethodParameter paramMethodParameter, final ModelAndViewContainer paramModelAndViewContainer, final NativeWebRequest paramNativeWebRequest,
			final WebDataBinderFactory paramWebDataBinderFactory) throws Exception {
		return SignInUtils.getUserSocialReference(this.socialUserService);
	}

}
